package main

import (
	"flag"
	"github.com/gin-gonic/gin"
	"log"
	"ttsApp/internal/config"
	"ttsApp/internal/db"
	"ttsApp/internal/handlers"
	"ttsApp/internal/models"
	"ttsApp/internal/redis"
)

func main() {
	var configPath string
	var configFrom string
	flag.StringVar(&configPath, "config-file", "./config/config.yaml", "指定配置文件路径 默认:./config/config.yaml")
	flag.StringVar(&configFrom, "config-from", "file", "指定配置文件来源 file nacos 默认从文件:file")
	// 解析命令行参数
	flag.Parse()
	// 打印出标志的值
	log.Printf("配置文件路径, %s!\n", configPath)
	if configFrom == "nacos" {
		config.InitServerByNacos()
	} else {
		config.Init(configPath)
	}

	db.DB = db.InitDB()

	redis.Client, redis.SyncClient = redis.InitRedis()
	handlers.StartMessageConsumer()
	models.AutoMigrate()
	r := gin.Default()
	r.POST("/api/tts-async", handlers.TTSAsyncApiHandel)
	err := r.Run(":" + config.C.Server.Port)
	if err != nil {
		log.Fatalf("Failed to start server: %v", err)
		return
	}
}
